// [THAM KHẢO - Java, KHÔNG chạy được trong Bedrock]
// File gốc: alats/config.class
// Bedrock Script API chỉ chạy JavaScript, không có JVM nên file .class này
// (thực chất là mã nguồn Java dạng text, không phải bytecode) không bao giờ
// có thể thực thi trong addon. Các ý tưởng hữu ích trong file này đã được
// viết lại hoàn toàn bằng JS thật và đưa vào hệ thống chính:
//   - Xem scripts/core/ChunkRequestCache.js (từ main.class - MainBridge)
//   - Xem scripts/config/PlayerConfigOverrides.js (từ config.class - Config)
//   - Xem scripts/core/ModuleRegistry.js (từ module.class + main2.class)
// File này được giữ nguyên chỉ để đối chiếu/tham khảo.

// config.class - Java-style configuration class
public class Config {
    private static Config instance;
    private Map<String, Object> configs;
    private Map<String, Object> playerConfigs;
    
    private Config() {
        this.configs = new HashMap<>();
        this.playerConfigs = new HashMap<>();
        this.loadDefaultConfigs();
    }
    
    public static Config getInstance() {
        if (instance == null) {
            instance = new Config();
        }
        return instance;
    }
    
    private void loadDefaultConfigs() {
        // Load default configurations
        Map<String, Object> chunkConfig = new HashMap<>();
        chunkConfig.put("maxLoadRadius", 16);
        chunkConfig.put("mediumLoadRadius", 10);
        chunkConfig.put("minLoadRadius", 6);
        chunkConfig.put("fastLoadSpeed", 1.5);
        chunkConfig.put("mediumLoadSpeed", 1.0);
        chunkConfig.put("slowLoadSpeed", 0.6);
        chunkConfig.put("highFPSThreshold", 50);
        chunkConfig.put("mediumFPSThreshold", 30);
        chunkConfig.put("verticalRange", 5);
        chunkConfig.put("diagonalRange", 4);
        chunkConfig.put("loadBatchSize", 16);
        chunkConfig.put("unloadDelay", 5000);
        
        this.configs.put("chunk", chunkConfig);
    }
    
    public Object getConfig(String key) {
        return this.configs.get(key);
    }
    
    public void setConfig(String key, Object value) {
        this.configs.put(key, value);
    }
    
    public Object getPlayerConfig(String playerId, String key) {
        Map<String, Object> playerConfig = (Map<String, Object>) this.playerConfigs.get(playerId);
        if (playerConfig == null) {
            return null;
        }
        return playerConfig.get(key);
    }
    
    public void setPlayerConfig(String playerId, String key, Object value) {
        Map<String, Object> playerConfig = (Map<String, Object>) this.playerConfigs.get(playerId);
        if (playerConfig == null) {
            playerConfig = new HashMap<>();
            this.playerConfigs.put(playerId, playerConfig);
        }
        playerConfig.put(key, value);
    }
    
    public void loadConfigs(Map<String, Object> configs) {
        for (Map.Entry<String, Object> entry : configs.entrySet()) {
            this.configs.put(entry.getKey(), entry.getValue());
        }
    }
    
    public Map<String, Object> getAllConfigs() {
        return new HashMap<>(this.configs);
    }
    
    public void reload() {
        this.configs.clear();
        this.playerConfigs.clear();
        this.loadDefaultConfigs();
    }
}